package com.das.mechanic_base.utils;

import android.content.Context;
import android.util.Log;

import com.das.mechanic_base.R;

import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.Locale;

import static com.das.mechanic_base.utils.X3TimeUtils.dateToLong;
import static com.das.mechanic_base.utils.X3TimeUtils.dateToString;

public class X3DateUtils {

    /**
     * 增加天数 计算增加之后的时间
     *
     * @param days
     * @return
     */
    public static String getAddDaysMonth(int days) {

        SimpleDateFormat sfDate = null;
        Calendar c = Calendar.getInstance();
        int beforeYear = c.get(Calendar.YEAR);

        c.add(Calendar.DAY_OF_MONTH, days);
        int afterYear = c.get(Calendar.YEAR);
        boolean isChina = LanguageUtiles.isZhRCN();
        if (isChina) {
            sfDate = new SimpleDateFormat("yyyy年MM月");
//            if (afterYear > beforeYear) {
//                sfDate = new SimpleDateFormat("yyyy年MM月");
//            } else {
//                sfDate = new SimpleDateFormat("MM月");
//            }
        } else {
            sfDate = new SimpleDateFormat("MMM, yyyy", Locale.ENGLISH);
//            if (afterYear > beforeYear) {
//                sfDate = new SimpleDateFormat("MMM, yyyy", Locale.ENGLISH);
//            } else {
//                sfDate = new SimpleDateFormat("MMM", Locale.ENGLISH);
//            }
        }
        return sfDate.format(c.getTime());
    }

    /**
     * 增加天数 计算增加之后的时间 返回月日
     *
     * @param days
     * @return
     */
    public static String getAddDaysMonthDay(int days) {
        boolean isChina = LanguageUtiles.isZhRCN();

        SimpleDateFormat sfDate = null;
        Calendar c = Calendar.getInstance();

        c.add(Calendar.DAY_OF_MONTH, days);
        if (isChina) {
            sfDate = new SimpleDateFormat("MM月dd日");
        } else {
            sfDate = new SimpleDateFormat("MMM dd", Locale.ENGLISH);
        }
        return sfDate.format(c.getTime());
    }

    /**
     * 将时间转换成时间戳
     * @return
     */
    public static String expriredDate(long time){
        String aDataStr = null;
        try {
            SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddhhmmss");
            Date date = sdf.parse(createDate());
            date.setTime(date.getTime() + time);
            aDataStr = sdf.format(date);
        } catch (ParseException e) {
            e.printStackTrace();
        }
        return aDataStr;
    }

    public static String createDate(){
        SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddhhmmss");
        String dataStr = sdf.format(new Date());
        return dataStr;
    }

    /**
     * 将 2012年02月 Feb, 2012 转换成 2012-02
     *
     * @param time
     * @return
     */
    public static String getSubmitTime(String time) {
        if (X3StringUtils.isEmpty(time)) {
            return "";
        }
        String newTime = "";

        try {
//            Date date;
            SimpleDateFormat sfDate;
            if (LanguageUtiles.isZhRCN()) {
                sfDate = new SimpleDateFormat("yyyy年MM月", Locale.CHINESE);
            } else {
                sfDate = new SimpleDateFormat("MMM, yyyy", Locale.ENGLISH);
            }
            newTime = dateToString(sfDate.parse(time), "yyyy-MM",Locale.CHINA);
        } catch (ParseException e) {
            e.printStackTrace();
            Log.e("SSSS", "转换报酬:" + e.toString() + "::" + LanguageUtiles.isZhRCN());
        }


        return newTime;
    }

    /**
     * 将 2012-02  转换成 2012年02月 Feb, 2012
     *
     * @param time
     * @return
     */
    public static String getShowTime(String time) {
        if (X3StringUtils.isEmpty(time)) {
            return "";
        }
        String newTime = "";

        try {
//            Date date;
            SimpleDateFormat sfDate = new SimpleDateFormat("yyyy-MM", Locale.getDefault());
            if (LanguageUtiles.isZhRCN()) {
                newTime =  dateToString(sfDate.parse(time), "yyyy年MM月",Locale.CHINA);
            } else {
                newTime =  dateToString(sfDate.parse(time), "MMM, yyyy",Locale.ENGLISH);
            }
        } catch (ParseException e) {
            e.printStackTrace();
            Log.e("SSSS", "转换报酬:" + e.toString() + "::" + LanguageUtiles.isZhRCN());
        }


        return newTime;
    }

    // 2012-02 转为 2012年02月
    public static String getTime(String time) {
        if (X3StringUtils.isEmpty(time)) {
            return "";
        }
        String newTime = "";

        try {
//            Date date;
            SimpleDateFormat sfDate;
                sfDate = new SimpleDateFormat("yyyy-MM", Locale.CHINESE);

            newTime = dateToString(sfDate.parse(time), "yyyy年MM月",Locale.CHINA);
        } catch (ParseException e) {
            e.printStackTrace();
            Log.e("SSSS", "转换报酬:" + e.toString() + "::" + LanguageUtiles.isZhRCN());
        }


        return newTime;
    }
    /**
     * 将 2012-02 转换成 2012-02-01 00:00:00
     *
     * @param time
     * @return
     */
    public static String getAloneSubmitTime(String time) {
        if (X3StringUtils.isEmpty(time)) {
            return "";
        }
        String newTime = "";

        try {
            Date date = stringToDate(time, "yyyy-MM");
            newTime = dateToString(date, "yyyy-MM-dd HH:mm:ss",Locale.CHINA);
        } catch (ParseException e) {
            e.printStackTrace();
        }


        return newTime;
    }

    /**
     * 将 2012-02-01 00:00:00 转换成 2012-02
     *
     * @param time
     * @return
     */
    public static String getShowAloneTime(String time) {
        if (X3StringUtils.isEmpty(time)) {
            return "";
        }
        String newTime = "";

        try {
            Date date = stringToDate(time, "yyyy-MM-dd HH:mm:ss");

            if (LanguageUtiles.isZhRCN()) {
                // 中文环境
                newTime = dateToString(date, "yyyy-MM",Locale.CHINA);

            } else {
                // 国外环境
                newTime = dateToString(date, "MMM, yyyy",Locale.ENGLISH);
            }
        } catch (ParseException e) {
            e.printStackTrace();
        }
        return newTime;
    }

    /**
     * 选择轮胎年限
     *
     * @param selectYear
     * @return
     */
    public static String getTyreTime(String selectYear) {
        Log.e("SSSS", "请求轮胎年限:" + selectYear);
        if (X3StringUtils.isEmpty(selectYear)) {
            return "";
        }
        boolean isChina = LanguageUtiles.isZhRCN();
        if (isChina) {
            return selectYear;
        }
        try {
            Date date = stringToDate(selectYear, "yyyy-MM");
            SimpleDateFormat sfDate = new SimpleDateFormat("MMM, yyyy", Locale.ENGLISH);
            Log.e("SSSS", "转换轮胎年限:" + sfDate.format(date));
            return sfDate.format(date);
        } catch (ParseException e) {
            e.printStackTrace();
        }
        return "";
    }

    /**
     * 是否过期
     */
    public static boolean isPast = false;

    /**
     * 短时间格式
     *
     * @param startTime
     * @return
     */
    public static String MonthWithYear(String startTime) {
        if (X3StringUtils.isEmpty(startTime)) {
            return "";
        }
        boolean isChina = LanguageUtiles.isZhRCN();

        Calendar instance = Calendar.getInstance();
        int currentYear = instance.get(Calendar.YEAR);
        int currentMonth = instance.get(Calendar.MONTH) + 1;

        SimpleDateFormat sfDate = null;
        try {
            Date date = stringToDate(startTime, "yyyy-MM-dd HH:mm:ss");

            Calendar calendar = Calendar.getInstance();
            calendar.setTime(date);
            int startYear = calendar.get(Calendar.YEAR);
            int startMonth = calendar.get(Calendar.MONTH) + 1;

            if (currentYear > startYear) {
                isPast = true;
            } else if (currentYear == startYear) {
                isPast = currentMonth >= startMonth;
            } else {
                isPast = false;
            }

            if (isChina) {
                sfDate = new SimpleDateFormat("yyyy年MM月", Locale.CHINESE);
            } else {
                sfDate = new SimpleDateFormat("MMM, yyyy", Locale.ENGLISH);
            }
            return sfDate.format(date);
        } catch (ParseException e) {
            e.printStackTrace();
        }
        return "";
    }

    /**
     * 年月日
     *
     * @param startTime
     * @return
     */
    public static String MonthWithDay(String startTime) {
        if (X3StringUtils.isEmpty(startTime)) {
            return "";
        }
        boolean isChina = LanguageUtiles.isZhRCN();
        Calendar instance = Calendar.getInstance();
        int currentYear = instance.get(Calendar.YEAR);
        SimpleDateFormat sfDate = null;
        try {
            Date date = stringToDate(startTime, "yyyy-MM-dd HH:mm:ss");
            Calendar calendar = Calendar.getInstance();
            calendar.setTime(date);
            int startYear = calendar.get(Calendar.YEAR);
            if (isChina) {
                if (currentYear == startYear) {
                    sfDate = new SimpleDateFormat("MM月dd日", Locale.CHINESE);
                } else {
                    sfDate = new SimpleDateFormat("yyyy年MM月dd日", Locale.CHINESE);
                }
            } else {
                if (currentYear == startYear) {
                    sfDate = new SimpleDateFormat("MMM dd", Locale.ENGLISH);
                } else {
                    sfDate = new SimpleDateFormat("MMM dd,yyyy", Locale.ENGLISH);
                }
            }
            return sfDate.format(date);
        } catch (ParseException e) {
            e.printStackTrace();
        }
        return "";
    }

    /**
     * 将时间装换为 年月日 时分
     *
     * @param startTime
     * @return
     */
    public static String SecondWithDay(String startTime) {
        if (X3StringUtils.isEmpty(startTime)) {
            return "";
        }
        boolean isChina = LanguageUtiles.isZhRCN();
        Calendar instance = Calendar.getInstance();
        int currentYear = instance.get(Calendar.YEAR);
        SimpleDateFormat sfDate = null;
        try {
            Date date = stringToDate(startTime, "yyyy-MM-dd HH:mm:ss");
            Calendar calendar = Calendar.getInstance();
            calendar.setTime(date);
            int startYear = calendar.get(Calendar.YEAR);
            if (isChina) {
                if (currentYear == startYear) {
                    sfDate = new SimpleDateFormat("MM月dd日 HH:mm", Locale.CHINESE);
                } else {
                    sfDate = new SimpleDateFormat("yyyy年MM月dd日 HH:mm", Locale.CHINESE);
                }
            } else {
                if (currentYear == startYear) {
                    sfDate = new SimpleDateFormat("MMM dd HH:mm", Locale.ENGLISH);
                } else {
                    sfDate = new SimpleDateFormat("MMM dd,yyyy HH:mm", Locale.ENGLISH);
                }
            }
            return sfDate.format(date);
        } catch (ParseException e) {
            e.printStackTrace();
        }
        return "";
    }


    /**
     * 返回 长时间格式
     *
     * @param startTime
     * @return
     */
    public static String LongDateWithTime(String startTime) {
        if (X3StringUtils.isEmpty(startTime)) {
            return "";
        }
        boolean isChina = LanguageUtiles.isZhRCN();
        Calendar instance = Calendar.getInstance();
        int currentYear = instance.get(Calendar.YEAR);
        SimpleDateFormat sfDate = null;
        try {
            Date date = stringToDate(startTime, "yyyy-MM-dd HH:mm:ss");
            Calendar calendar = Calendar.getInstance();
            calendar.setTime(date);
            int startYear = calendar.get(Calendar.YEAR);
            if (isChina) {
                if (currentYear == startYear) {
                    sfDate = new SimpleDateFormat("MM月dd日 HH:mm", Locale.CHINESE);
                } else {
                    sfDate = new SimpleDateFormat("yyyy年MM月dd日 HH:mm", Locale.CHINESE);
                }
            } else {
                if (currentYear == startYear) {
                    sfDate = new SimpleDateFormat("HH:mm, MMM dd", Locale.ENGLISH);
                } else {
                    sfDate = new SimpleDateFormat("HH:mm, MMM dd,yyyy", Locale.ENGLISH);
                }
            }
            return sfDate.format(date);
        } catch (ParseException e) {
            e.printStackTrace();
        }
        return "";
    }

    /**
     * 返回 长时间格式
     *
     * @param startTime
     * @return
     */
    public static String HomeLongDateWithTime(String startTime,Context mContext) {
        if (X3StringUtils.isEmpty(startTime)) {
            return "";
        }
        boolean isChina = LanguageUtiles.isZhRCN();
        Calendar instance = Calendar.getInstance();
        int currentYear = instance.get(Calendar.YEAR);
        int currentMonth = instance.get(Calendar.MONTH) + 1;
        int currentDay = instance.get(Calendar.DATE);
        SimpleDateFormat sfDate = null;
        try {
            Date date = stringToDate(startTime, "yyyy-MM-dd HH:mm:ss");
            Calendar calendar = Calendar.getInstance();
            calendar.setTime(date);
            int startYear = calendar.get(Calendar.YEAR);
            int startMonth = calendar.get(Calendar.MONTH) + 1;
            int startDay = calendar.get(Calendar.DATE);

            String homeTaskTime = "";

            if (isChina) {
                if (currentYear == startYear) {
                    if (currentMonth == startMonth) {
                        if (currentDay - startDay == 0) {
                            sfDate = new SimpleDateFormat("HH:mm", Locale.CHINESE);
                            homeTaskTime = mContext.getString(R.string.x3_today_ye) + " " + sfDate.format(date);
                        } else if (currentDay - startDay == 1) {
                            sfDate = new SimpleDateFormat("HH:mm", Locale.CHINESE);
                            homeTaskTime = mContext.getString(R.string.x3_yesterday) + " " + sfDate.format(date);
                        }else if (currentDay - startDay == -1) {
                            sfDate = new SimpleDateFormat("HH:mm", Locale.CHINESE);
                            homeTaskTime = mContext.getString(R.string.x3_tomorrow) + " " + sfDate.format(date);
                        }else {
                            sfDate = new SimpleDateFormat("MM月dd日 HH:mm", Locale.CHINESE);
                            homeTaskTime = sfDate.format(date);
                        }

                    }else {
                        sfDate = new SimpleDateFormat("MM月dd日 HH:mm", Locale.CHINESE);
                        homeTaskTime = sfDate.format(date);
                    }

                } else {
                    sfDate = new SimpleDateFormat("yyyy年MM月dd日 HH:mm", Locale.CHINESE);
                    homeTaskTime = sfDate.format(date);
                }
            } else {
                if (currentYear == startYear) {

                    if (currentMonth == startMonth) {
                        if (currentDay - startDay == 0) {
                            sfDate = new SimpleDateFormat("HH:mm", Locale.ENGLISH);
                            homeTaskTime = mContext.getString(R.string.x3_today_ye) + " " + sfDate.format(date);
                        } else if (currentDay - startDay == 1) {
                            sfDate = new SimpleDateFormat("HH:mm", Locale.ENGLISH);
                            homeTaskTime = mContext.getString(R.string.x3_yesterday) + " " + sfDate.format(date);
                        }else if (currentDay - startDay == -1) {
                            sfDate = new SimpleDateFormat("HH:mm", Locale.ENGLISH);
                            homeTaskTime = mContext.getString(R.string.x3_tomorrow) + " " + sfDate.format(date);

                        }else {
                            sfDate = new SimpleDateFormat("MM月dd日 HH:mm", Locale.ENGLISH);
                            homeTaskTime = sfDate.format(date);
                        }

                    }else {
                        sfDate = new SimpleDateFormat("MM月dd日 HH:mm", Locale.CHINESE);
                        homeTaskTime = sfDate.format(date);
                    }

                } else {
                    sfDate = new SimpleDateFormat("HH:mm, MMM dd,yyyy", Locale.ENGLISH);
                    homeTaskTime = sfDate.format(date);
                }
            }
            return homeTaskTime;
        } catch (ParseException e) {
            e.printStackTrace();
        }
        return "";
    }

    /**
     * 月日格式下 计算差值
     *
     * @param time
     * @param currentTime
     * @return
     */
    public static int checkTime(String time, String currentTime) {

        SimpleDateFormat sdf = new SimpleDateFormat("MM月dd日");

        int result = 0;
        //得到指定模范的时间
        try {
            Date current_date = sdf.parse(currentTime);
            Date info_time = sdf.parse(time);

            result = (int) Math.abs(((current_date.getTime() - info_time.getTime()) / (24 * 3600 * 1000)));

        } catch (ParseException e) {
            e.printStackTrace();
        }
        return result;
    }

    /**
     * 是否是传入日期比当前日期大
     */
    public static boolean isAfter = false;

    /**
     * 计算与当前时间相减 计算而得的相对时间
     *
     * @param startTime
     * @return
     */
    public static String RelativeTime(String startTime, Context mContext) {
        if (X3StringUtils.isEmpty(startTime)) {
            return "";
        }
        Calendar instance = Calendar.getInstance();
        long currentTime = instance.getTime().getTime();

        try {
            long startLong = stringToLong(startTime, "yyyy-MM-dd HH:mm:ss");
            long result = currentTime - startLong;
            isAfter = result < 0;

            Calendar start = Calendar.getInstance();
            start.setTime(stringToDate(startTime, "yyyy-MM-dd HH:mm:ss"));
            int startHour = start.get(Calendar.HOUR_OF_DAY);

            long days = result / (1000 * 60 * 60 * 24);
            long hours = (result - days * (1000 * 60 * 60 * 24)) / (1000 * 60 * 60);
            long minutes = (result - days * (1000 * 60 * 60 * 24) - hours * (1000 * 60 * 60)) / (1000 * 60);

            if (days == 0) {
                if ((hours <= 1 && minutes <= 0) || hours == 0) {
                    // 刚刚
                    return mContext.getString(R.string.x3_just_now);
                }
                if (hours > startHour && hours < startHour + 24) {
                    if (!isAfter) {
                        return mContext.getString(R.string.x3_yesterday);
                    }
                }
                // X小时前（1小时外，今天内）
                return String.format(mContext.getString(R.string.x3_hours_ago), hours, getCurrentUnit(hours, mContext, false));
            } else {
                if (days == 1) {
                    if (hours < startHour) {
                        return mContext.getString(R.string.x3_yesterday);
                    }
                }

                long weeks = days / 7;
                if (weeks < 1) {
                    return String.format(mContext.getString(R.string.x3_week_ago), days, getCurrentUnit(days, mContext, true));
                }

                if (weeks < 4 || days < 30) {
                    return String.format(mContext.getString(R.string.x3_weeks_ago), weeks, getCurrentUnit(weeks, mContext, true));
                }

                long month = days / 30;

                if (month < 12 || days < 365) {
                    return String.format(mContext.getString(R.string.x3_months_ago), month, getCurrentUnit(month, mContext, false));
                }
                long years = days / 365;
                return String.format(mContext.getString(R.string.x3_years_ago), years, getCurrentUnit(years, mContext, false));
            }

        } catch (ParseException e) {
            e.printStackTrace();
        }

        return "";
    }

    /**
     * 计算与当前时间相减 计算而得的相对时间
     *
     * @param startTime
     * @return
     */
    public static String RelativeCrmTime(String startTime, Context mContext) {
        if (X3StringUtils.isEmpty(startTime)) {
            return "";
        }
        Calendar instance = Calendar.getInstance();
        long currentTime = instance.getTime().getTime();

        try {
            long startLong = stringToLong(startTime, "yyyy-MM-dd HH:mm:ss");
            long result = Math.abs(currentTime - startLong);
            Calendar start = Calendar.getInstance();
            start.setTime(stringToDate(startTime, "yyyy-MM-dd HH:mm:ss"));

            int startHour = start.get(Calendar.HOUR_OF_DAY);

            isAfter = (currentTime - startLong) < 0;

            long days = result / (1000 * 60 * 60 * 24);
            long hours = (result - days * (1000 * 60 * 60 * 24)) / (1000 * 60 * 60);
            long minutes = (result - days * (1000 * 60 * 60 * 24) - hours * (1000 * 60 * 60)) / (1000 * 60);

            if (days == 0) {
                if ((hours <= 1 && minutes <= 0) || hours == 0) {
                    // 刚刚
                    return mContext.getString(R.string.x3_just_now);
                }
                // X小时前（1小时外，今天内）
                if (hours == 1) {
                    return String.format(mContext.getString(R.string.x3_hours_lenth), hours);
                }
                if (hours > startHour && hours < startHour + 24) {
                    if (!isAfter) {
                        return mContext.getString(R.string.x3_yesterday);
                    }
                }
                return String.format(mContext.getString(R.string.x3_hours_lenth), hours) + mContext.getString(R.string.x3_time_unit);
            } else {
                long weeks = days / 7;
                if (weeks < 1) {
                    return String.format(mContext.getString(R.string.x3_week_lenth), days) + getCurrentUnit(days, mContext, false);
                }
                if (weeks < 4 || days < 30) {
                    return String.format(mContext.getString(R.string.weeks_lenth), weeks) + getCurrentUnit(weeks, mContext, true);
                }
                long month = days / 30;
                if (month < 12 || days < 365) {
                    return String.format(mContext.getString(R.string.x3_months_lenth), month) + getCurrentUnit(month, mContext, false);
                }
                long years = days / 365;
                return String.format(mContext.getString(R.string.x3_years_lenth), years) + getCurrentUnit(years, mContext, false);
            }

        } catch (ParseException e) {
            e.printStackTrace();
        }

        return "";
    }

    /**
     * 计算与当前时间相减 计算而得的相对时间
     *
     * @param startTime
     * @return
     */
    public static String HomeRelativeTime(String startTime, Context mContext) {
        if (X3StringUtils.isEmpty(startTime)) {
            return "";
        }
        Calendar instance = Calendar.getInstance();
        long currentTime = instance.getTime().getTime();

        try {
            long startLong = stringToLong(startTime, "yyyy-MM-dd HH:mm:ss");

            long result = currentTime - startLong;

            long days = result / (1000 * 60 * 60 * 24);
            long hours = (result - days * (1000 * 60 * 60 * 24)) / (1000 * 60 * 60);
            long minutes = (result - days * (1000 * 60 * 60 * 24) - hours * (1000 * 60 * 60)) / (1000 * 60);

            if (days == 0) {
                if (hours == 0) {
                    if (minutes == 0) {
                        minutes = 1;
                    }
                    return String.format(mContext.getString(R.string.x3_mins_ago), minutes, getCurrentUnit(minutes, mContext, false));
                }
                return String.format(mContext.getString(R.string.x3_hours_ago), hours, getCurrentUnit(hours, mContext, false));

            } else {
                if (days <= 30) {
                    return String.format(mContext.getString(R.string.x3_week_ago), days, getCurrentUnit(days, mContext, true));
                }

                long month = days / 30;

                if (month < 12 || days < 365) {
                    return String.format(mContext.getString(R.string.x3_months_ago), month, getCurrentUnit(month, mContext, false));
                }
                long years = days / 365;
                return String.format(mContext.getString(R.string.x3_years_ago), years, getCurrentUnit(years, mContext, false));
            }

        } catch (ParseException e) {
            e.printStackTrace();
        }

        return "";
    }

    public static String longToStringForStaff(long time) {
        if (time == 0) {
            return "";
        }
        boolean isChina = LanguageUtiles.isZhRCN();
        SimpleDateFormat sdf = null;
        if (isChina) {
            sdf = new SimpleDateFormat("MM月dd日 HH:mm");
        }else {
            sdf = new SimpleDateFormat("MMM dd HH:mm");
        }

        Date date = new Date(time);
        return sdf.format(date);
    }

    public static long staffStringToLong(String strTime) {
        if (X3StringUtils.isEmpty(strTime)) {
            return 0;
        }
        boolean isChina = LanguageUtiles.isZhRCN();
        if (isChina) {
            try {
                return stringToLong(strTime,"MM月dd日 HH:mm");
            } catch (ParseException e) {
                e.printStackTrace();
            }
        }
        try {
            return stringToLong(strTime,"MMM dd HH:mm");
        } catch (ParseException e) {
            e.printStackTrace();
        }
        return 0;
    }

    public static Date staffStringToDate(String strTime) {
        if (X3StringUtils.isEmpty(strTime)) {
            return new Date();
        }
        boolean isChina = LanguageUtiles.isZhRCN();
        if (isChina) {
            try {
                return stringToDate(strTime,"MM月dd日 HH:mm");
            } catch (ParseException e) {
                e.printStackTrace();
            }
        }
        try {
            return stringToDate(strTime,"MMM dd HH:mm");
        } catch (ParseException e) {
            e.printStackTrace();
        }
        return new Date();
    }

    public static String getStaffNextYearTime(String strTime) {
        if (X3StringUtils.isEmpty(strTime)) {
            return "";
        }
        String selectTime = "";
        Calendar calendar = Calendar.getInstance();
        boolean isChina = LanguageUtiles.isZhRCN();
        if (isChina) {
            try {
                Date date = stringToDate(strTime, "MM月dd日 HH:mm");
                calendar.setTime(date);
                calendar.add(Calendar.YEAR,1);

                Date time = calendar.getTime();
                selectTime = dateToString(time,"yyyy年MM月dd日 HH:mm",Locale.CHINA);

            } catch (ParseException e) {
                e.printStackTrace();
            }


        }else {
            try {
                Date date = stringToDate(strTime, "MMM dd HH:mm");
                calendar.setTime(date);
                calendar.add(Calendar.YEAR,1);

                Date time = calendar.getTime();
                selectTime = dateToString(time,"MMM dd, yyyy HH:mm",Locale.CHINA);

            } catch (ParseException e) {
                e.printStackTrace();
            }
        }
        return selectTime;
    }

    /**
     * string TO long
     *
     * @param strTime
     * @param formatType
     * @return
     * @throws ParseException
     */
    public static long stringToLong(String strTime, String formatType)
            throws ParseException {
        Date date = stringToDate(strTime, formatType); // String类型转成date类型
        if (date == null) {
            return 0;
        } else {
            long currentTime = dateToLong(date); // date类型转成long类型
            return currentTime;
        }
    }

    /**
     * string to Date
     *
     * @param strTime
     * @param formatType
     * @return
     * @throws ParseException
     */
    public static Date stringToDate(String strTime, String formatType)
            throws ParseException {
        SimpleDateFormat formatter = new SimpleDateFormat(formatType);
        Date date = formatter.parse(strTime);
        return date;
    }

    /**
     * 判断车友圈的时间
     *
     * @param mgtCreate
     * @return
     */
    public static String getTimeAfter(String mgtCreate) {

        DateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm");

        String time = "";
//
//        try {
//            Date sendDate = df.parse(mgtCreate);
//
//            Calendar calendar = Calendar.getInstance();
//            calendar.setTime(sendDate);
//            int year = calendar.get(Calendar.YEAR);
//            int month = calendar.get(Calendar.MONTH) + 1;
//            int day = calendar.get(Calendar.DAY_OF_MONTH);
//            int hour = calendar.get(Calendar.HOUR_OF_DAY);
//            int second = calendar.get(Calendar.MINUTE);
//
//            Date currentDate = new Date(System.currentTimeMillis());
//
//            Calendar calendar1 = Calendar.getInstance();
//            calendar.setTime(currentDate);
//            int day1 = calendar1.get(Calendar.DAY_OF_MONTH);
//
//            long diff = currentDate.getTime() - sendDate.getTime();
//            long days = diff / (1000 * 60 * 60 * 24);
//            long hours = (diff - days * (1000 * 60 * 60 * 24)) / (1000 * 60 * 60);
//            long minutes = (diff - days * (1000 * 60 * 60 * 24) - hours * (1000 * 60 * 60)) / (1000 * 60);
//            // 2019-07-13 17:01:45
//            if (days == 0) {
//                if (day1 - day > 0) {
//                    time = R.string.yesterday + hour + ":" + (second < 10 ? "0" + second : second);
//                } else {
//                    if (hours == 0) {
//                        if (minutes > 0) {
//                            time = minutes + mContext.getString(R.string.before_minute) + "";
//                        } else {
//                            time = "" + mContext.getString(R.string.now);
//                        }
//                    } else {
//                        time = mContext.getString(R.string.today) + hour + ":" + (second < 10 ? "0" + second : second);
//                    }
//                }
//
//            } else if (days == 1 && hour <= 0 && second <= 0) {
//
//                time = mContext.getString(R.string.yesterday) + hour + ":" + (second < 10 ? "0" + second : second);
//
//            } else if ((days == 2 && hour <= 0 && second <= 0) || (days == 1 && (hour > 0 || second > 0))) {
//                time = mContext.getString(R.string.two_days_ago) + hour + ":" + (second < 10 ? "0" + second : second);
//            } else {
//                time = (month < 10 ? "0" + month : month) + "-" + (day < 10 ? "0" + day : day) + "  " + hour + ":" + (second < 10 ? "0" + second : second);
//            }
//
//        } catch (ParseException e) {
//            e.printStackTrace();
//            Log.e("SSSS", "计算时间错误：" + e.toString());
//        }

        return time;
    }

    /* 获取年月日
     *
     * @param time
     * @return
     */
    public static String getMonthAndDay(String time) {
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");// 输入日期的格式
        Date date1 = null;
        Calendar calendar = Calendar.getInstance();

        try {
            date1 = simpleDateFormat.parse(time);
            calendar.setTime(date1);
            int year = calendar.get(Calendar.YEAR);
            int month = calendar.get(Calendar.MONTH) + 1;
            int day = calendar.get(Calendar.DAY_OF_MONTH);
            int hour = calendar.get(Calendar.HOUR_OF_DAY);
            int second = calendar.get(Calendar.MINUTE);

            return month + "月" + day + "日";
        } catch (ParseException e) {
            e.printStackTrace();
        }

        return null;
    }

    public static long getDayAfter(String joinTime) {

        long days = 0;
        DateFormat df = new SimpleDateFormat("yyyy-MM-dd");

        try {
            Date joinDate = df.parse(joinTime);
            Date currentDate = new Date(System.currentTimeMillis());
            long diff = currentDate.getTime() - joinDate.getTime();
            days = diff / (1000 * 60 * 60 * 24) + 1;

        } catch (ParseException e) {
            e.printStackTrace();
        }

        return days;
    }

    /**
     * 获取时间相减得到的天数
     * @param joinTime
     * @return
     */
    public static int getDayTimeAfter(String joinTime) {

        int days = 0;
        DateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

        try {
            Date joinDate = df.parse(joinTime);
            Date currentDate = new Date(System.currentTimeMillis());
            long diff = currentDate.getTime() - joinDate.getTime();
            days = (int) (diff / (1000 * 60 * 60 * 24) + 1);

        } catch (ParseException e) {
            e.printStackTrace();
        }

        return days;
    }

    public static String getFormatHMS(long time) {
        time = time / 1000;
        int s = (int) (time % 60);
        int m = (int) (time / 60);
        int h = (int) (time / 3600);
        return String.format("%02d:%02d:%02d", h, m, s);

    }

    public static long getHomeTime(String startTime, String endTime) {
        DateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        try {
            Date d1 = df.parse(startTime);
            Date d2 = df.parse(endTime);
            long diff = d2.getTime() - d1.getTime();//这样得到的差值是微秒级别
            return diff;
        } catch (Exception e) {
            e.printStackTrace();
        }
        return 0;
    }

    /**
     * 计算剩余时间
     *
     * @param targetTime
     * @return
     */
    public static String getHomeTimeLeft(String targetTime, Context mContext) {
        if (X3StringUtils.isEmpty(targetTime)) {
            return "";
        }
        Calendar instance = Calendar.getInstance();
        long currentTime = instance.getTime().getTime();

        try {
            long startLong = stringToLong(targetTime, "yyyy-MM-dd HH:mm:ss");
            long result = startLong - currentTime;
            if (result <= 0) {
                return "refresh";
            }

            long days = result / (1000 * 60 * 60 * 24);
            long hours = (result - days * (1000 * 60 * 60 * 24)) / (1000 * 60 * 60);
            long minutes = (result - days * (1000 * 60 * 60 * 24) - hours * (1000 * 60 * 60)) / (1000 * 60);
            long seconds = (result - days * (1000 * 60 * 60 * 24) - hours * (1000 * 60 * 60) - minutes * (1000 * 60)) / 1000;

            if (days == 0) {
                if (hours == 0) {
                    if (minutes == 0) {
                        return String.format(mContext.getString(R.string.x3_seconds_time_left), seconds, getCurrentUnit(minutes, mContext, false));
                    } else {
                        return String.format(mContext.getString(R.string.x3_minutes_time_left), minutes, getCurrentUnit(minutes, mContext, false));
                    }
                } else {
                    return String.format(mContext.getString(R.string.x3_hours_time_left), hours, getCurrentUnit(minutes, mContext, false));
                }

            } else {
                if (days < 7) {
                    /**
                     * 剩余超过1天，不到7天
                     */
                    return String.format(mContext.getString(R.string.x3_days_time_left), days, getCurrentUnit(minutes, mContext, true));
                }
                long weeks = days / 7;
                if (weeks < 4) {
                    /**
                     * 剩余超过1周，不到4周
                     */
                    return String.format(mContext.getString(R.string.x3_weeks_time_left), weeks, getCurrentUnit(minutes, mContext, true));
                }
                long months = days / 30;
                if (months == 0) {
                    months = 1;
                }
                if (months < 12) {
                    /**
                     * 剩余超过1个月，不到12个月
                     */
                    return String.format(mContext.getString(R.string.x3_months_time_left), months, getCurrentUnit(minutes, mContext, false));
                }
                long years = days / 365;
                /**
                 * 剩余超过1个月，不到12个月
                 */
                return String.format(mContext.getString(R.string.x3_years_time_left), years, getCurrentUnit(minutes, mContext, false));


            }
        } catch (ParseException e) {
            e.printStackTrace();
        }

        return "";
    }

    private static String getCurrentUnit(long num, Context mContext, boolean isWeek) {
        if (LanguageUtiles.isDe() && isWeek) {
            return (num == 1 || num == 0) ? "" : mContext.getString(R.string.x3_time_unit_have_e);
        }
        return (num == 1 || num == 0) ? "" : mContext.getString(R.string.x3_time_unit);
    }

    /**
     * 计算与当前时间相差几分钟
     * @param startTime
     * @return
     */
    public static int getHomeCompare(String startTime) {
        if (X3StringUtils.isEmpty(startTime)) {
            return 0;
        }
        Calendar instance = Calendar.getInstance();
        long currentTime = instance.getTime().getTime();

        try {
            long startLong = stringToLong(startTime, "yyyy-MM-dd HH:mm:ss");

            long result = currentTime - startLong;

            long minutes = result / 1000 / 60;

            return (int) minutes;

        } catch (ParseException e) {
            e.printStackTrace();
        }

        return 0;
    }

    /**
     * 是否比当前时间大
     * 0 大  超过当前时间
     * 1 正好到当前时间
     * 2 小 还未到当前时间
     * @param targetTime
     * @return
     */
    public static int isPkCurrentTime(String targetTime) {
        if (X3StringUtils.isEmpty(targetTime)) {
            return 2;
        }
        Calendar instance = Calendar.getInstance();
        long currentTime = instance.getTime().getTime();
        try {
            long startLong = stringToLong(targetTime, "yyyy-MM-dd HH:mm:ss");
            if (startLong == currentTime) {
                return 1;
            }else if (startLong > currentTime) {
                return 0;
            }
            return 2;

        } catch (ParseException e) {
            e.printStackTrace();
        }
        return 2;
    }

    /**
     * 计算剩余时间
     *
     * @param targetTime
     * @return
     */
    public static String getHomeTimeIn(String targetTime, Context mContext) {
        if (X3StringUtils.isEmpty(targetTime)) {
            return "";
        }
        Calendar instance = Calendar.getInstance();
        long currentTime = instance.getTime().getTime();

        try {
            long startLong = stringToLong(targetTime, "yyyy-MM-dd HH:mm:ss");
            long result = startLong - currentTime;

            if (result <= 0) {
                return "refresh";
            }

            long days = result / (1000 * 60 * 60 * 24);
            long hours = (result - days * (1000 * 60 * 60 * 24)) / (1000 * 60 * 60);
            long minutes = (result - days * (1000 * 60 * 60 * 24) - hours * (1000 * 60 * 60)) / (1000 * 60);
            long seconds = (result - days * (1000 * 60 * 60 * 24) - hours * (1000 * 60 * 60) - minutes * (1000 * 60)) / 1000;

            if (days == 0) {
                if (hours == 0) {
                    if (minutes == 0) {
                        if (seconds == 1) {
                            return String.format(mContext.getResources().getString(R.string.x3_seconds_time_in), seconds);
                        }
                        return String.format(mContext.getResources().getString(R.string.x3_seconds_time_in), seconds) + mContext.getString(R.string.x3_time_unit);
                    } else {
                        if (minutes == 1) {
                            return String.format(mContext.getResources().getString(R.string.x3_minutes_time_in), minutes);
                        }
                        return String.format(mContext.getResources().getString(R.string.x3_minutes_time_in), minutes) + mContext.getString(R.string.x3_time_unit);
                    }
                } else {
                    if (hours == 1) {
                        return String.format(mContext.getResources().getString(R.string.x3_hours_time_in), hours);
                    }
                    return String.format(mContext.getResources().getString(R.string.x3_hours_time_in), hours) + mContext.getString(R.string.x3_time_unit);
                }

            } else {
                if (days == 1) {
                    return String.format(mContext.getResources().getString(R.string.x3_days_time_in), days);
                }
                if (days < 7) {
                    /**
                     * 剩余超过1天，不到7天
                     */
                    return String.format(LanguageUtiles.appContext.getApplicationContext().getString(R.string.x3_days_time_in), days) + mContext.getString(R.string.x3_time_unit);
                }
                long weeks = days / 7;
                if (weeks == 1) {
                    return String.format(mContext.getResources().getString(R.string.x3_weeks_time_in), weeks);
                }
                if (weeks < 4) {
                    /**
                     * 剩余超过1周，不到4周
                     */
                    return String.format(mContext.getApplicationContext().getString(R.string.x3_weeks_time_in), weeks) + mContext.getString(R.string.x3_time_unit);
                }
                long months = days / 30;
                if (months == 1 || months == 0) {
                    months = 1;
                    return String.format(mContext.getApplicationContext().getString(R.string.x3_months_time_in), months);
                }
                if (months < 12) {
                    /**
                     * 剩余超过1个月，不到12个月
                     */
                    return String.format(mContext.getApplicationContext().getString(R.string.x3_months_time_in), months) + mContext.getString(R.string.x3_time_unit);
                }
                long years = days / 365;
                if (years == 1) {
                    return String.format(mContext.getApplicationContext().getString(R.string.x3_years_time_in), years);
                }
                /**
                 * 剩余超过1个月，不到12个月
                 */
                return String.format(mContext.getApplicationContext().getString(R.string.x3_years_time_in), years) + mContext.getString(R.string.x3_time_unit);


            }
        } catch (ParseException e) {
            e.printStackTrace();
        }

        return "";
    }

    /**
     * 计算剩余时间
     *
     * @param targetTime
     * @return
     */
    public static String getHomeTimeDelay(String targetTime, Context mContext) {
        if (X3StringUtils.isEmpty(targetTime)) {
            return "";
        }
        Calendar instance = Calendar.getInstance();
        long currentTime = instance.getTime().getTime();

        try {
            long startLong = stringToLong(targetTime, "yyyy-MM-dd HH:mm:ss");
            long result = Math.abs(currentTime - startLong);

            long days = result / (1000 * 60 * 60 * 24);
            long hours = (result - days * (1000 * 60 * 60 * 24)) / (1000 * 60 * 60);
            long minutes = (result - days * (1000 * 60 * 60 * 24) - hours * (1000 * 60 * 60)) / (1000 * 60);
            long seconds = (result - days * (1000 * 60 * 60 * 24) - hours * (1000 * 60 * 60) - minutes * (1000 * 60)) / 1000;

            if (days == 0) {
                if (hours == 0) {
                    if (minutes == 0) {
                        if (seconds == 1) {
                            return String.format(mContext.getString(R.string.x3_seconds_time_delay), seconds) + mContext.getString(R.string.x3_time_unit);
                        }
                        return String.format(mContext.getString(R.string.x3_seconds_time_delay), seconds);
                    } else {
                        if (minutes == 1) {
                            return String.format(mContext.getString(R.string.x3_minutes_time_delay), minutes);
                        }
                        return String.format(mContext.getString(R.string.x3_minutes_time_delay), minutes) + mContext.getString(R.string.x3_time_unit);
                    }
                } else {
                    if (hours == 1) {
                        return String.format(mContext.getString(R.string.x3_hours_time_delay), hours);
                    }
                    return String.format(mContext.getString(R.string.x3_hours_time_delay), hours) + mContext.getString(R.string.x3_time_unit);
                }

            } else {
                if (days == 1) {
                    return String.format(mContext.getString(R.string.x3_days_time_delay), days);
                }
                if (days < 7) {
                    /**
                     * 剩余超过1天，不到7天
                     */
                    return String.format(mContext.getString(R.string.x3_days_time_delay), days) + mContext.getString(R.string.x3_time_unit);
                }
                long weeks = days / 7;
                if (weeks == 1) {
                    return String.format(mContext.getString(R.string.x3_weeks_time_delay), weeks);
                }
                if (weeks < 4) {
                    /**
                     * 剩余超过1周，不到4周
                     */
                    return String.format(mContext.getString(R.string.x3_weeks_time_delay), weeks) + mContext.getString(R.string.x3_time_unit);
                }
                long months = days / 30;
                if (months == 1 || months == 0) {
                    months = 1;
                    return String.format(mContext.getString(R.string.x3_months_time_delay), months);
                }
                if (months < 12) {
                    /**
                     * 剩余超过1个月，不到12个月
                     */
                    return String.format(mContext.getString(R.string.x3_months_time_delay), months) + mContext.getString(R.string.x3_time_unit);
                }
                long years = days / 365;
                if (years == 1) {
                    return String.format(mContext.getString(R.string.x3_years_time_delay), years);
                }
                /**
                 * 剩余超过1个月，不到12个月
                 */
                return String.format(mContext.getString(R.string.x3_years_time_delay), years) + mContext.getString(R.string.x3_time_unit);


            }
        } catch (ParseException e) {
            e.printStackTrace();
        }

        return "";
    }

    /**
     * 根据当前日期获得是星期几
     * time=yyyy-MM-dd
     *
     * @return
     */
    public static String getWeek(String time) {
        String Week = "";
        SimpleDateFormat format = new SimpleDateFormat("yyyy年MM月dd日");
        Calendar c = Calendar.getInstance();
        try {
            c.setTime(format.parse(time));
        } catch (ParseException e) {
            e.printStackTrace();
        }

        int wek = c.get(Calendar.DAY_OF_WEEK);

        if (wek == 1) {
            Week += "日";
        }
        if (wek == 2) {
            Week += "一";
        }
        if (wek == 3) {
            Week += "二";
        }
        if (wek == 4) {
            Week += "三";
        }
        if (wek == 5) {
            Week += "四";
        }
        if (wek == 6) {
            Week += "五";
        }
        if (wek == 7) {
            Week += "六";
        }
        return Week;
    }

    /**
     * 年月日相比较
     *
     * @param yearAndDay
     * @return
     */
    public static boolean checkDayOrYear(String yearAndDay) {
        // 输入日期的格式
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
        Date currentDate = new Date(System.currentTimeMillis());
        String format = simpleDateFormat.format(currentDate);

        Log.e("SSSS", "计算强提醒时间:" + format + "::" + yearAndDay);

        Date dt1 = null;
        Date dt2 = null;
        try {
            dt1 = simpleDateFormat.parse(yearAndDay);
            dt2 = simpleDateFormat.parse(format);
        } catch (ParseException e) {
            e.printStackTrace();
        }

        if (dt1.getTime() >= dt2.getTime()) {
            return false;
        } else if (dt1.getTime() < dt2.getTime()) {
            return true;
        }
        return false;
    }

    /**
     * 获取当前的年月日
     *
     * @return
     */
    public static String getCurrentYearAndDay() {
//        HH:mm:ss
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
        Date currentDate = new Date(System.currentTimeMillis());
        String format = simpleDateFormat.format(currentDate);
        return format;
    }

    /**
     * 获取两个日期之间的间隔天数
     *
     * @return
     */
    public static int getGapCount(Date startDate, Date endDate) {
        Calendar fromCalendar = Calendar.getInstance();
        fromCalendar.setTime(startDate);
        fromCalendar.set(Calendar.HOUR_OF_DAY, 0);
        fromCalendar.set(Calendar.MINUTE, 0);
        fromCalendar.set(Calendar.SECOND, 0);
        fromCalendar.set(Calendar.MILLISECOND, 0);

        Calendar toCalendar = Calendar.getInstance();
        toCalendar.setTime(endDate);
        toCalendar.set(Calendar.HOUR_OF_DAY, 0);
        toCalendar.set(Calendar.MINUTE, 0);
        toCalendar.set(Calendar.SECOND, 0);
        toCalendar.set(Calendar.MILLISECOND, 0);

        return (int) ((toCalendar.getTime().getTime() - fromCalendar.getTime().getTime()) / (1000 * 60 * 60 * 24));
    }

    /**
     * 判断给定字符串时间是否为今日(效率不是很高，不过也是一种方法)
     *
     * @param sdate
     * @return boolean
     */
    public static boolean isToday(String sdate) {
        if (X3StringUtils.isEmpty(sdate)) {
            return false;
        }
        Date date = new Date(System.currentTimeMillis());

        String current = dateToString(date, "yyyy-MM-dd",Locale.CHINA);
        if (X3StringUtils.isEmpty(current)) {
            return false;
        }
        if (current.equals(sdate)) {
            return true;
        }
        return false;
    }


    public static String getTimeToNow(String startTime, Context mContext) {
        if (X3StringUtils.isEmpty(startTime)) {
            return "";
        }
        Calendar instance = Calendar.getInstance();
        long currentTime = instance.getTime().getTime();

        try {
            long startLong = stringToLong(startTime, "yyyy-MM-dd HH:mm:ss");
            if(currentTime > startLong){

            long result = currentTime - startLong;

            long days = result / (1000 * 60 * 60 * 24);
            long hours = (result - days * (1000 * 60 * 60 * 24)) / (1000 * 60 * 60);
            long minutes = (result - days * (1000 * 60 * 60 * 24) - hours * (1000 * 60 * 60)) / (1000 * 60);

            if (days == 0) {
                if (hours == 0) {
                    if (minutes == 0) {
                        minutes = 1;
                    }
                    return String.format(mContext.getString(R.string.x3_mins_ago), minutes, getCurrentUnit(minutes, mContext, false));
                }
                return String.format(mContext.getString(R.string.x3_hours_ago), hours, getCurrentUnit(hours, mContext, false));

            } else {
                if (days <= 30) {
                    return String.format(mContext.getString(R.string.x3_week_ago), days, getCurrentUnit(days, mContext, true));
                }

                long month = days / 30;

                if (month < 12 || days < 365) {
                    return String.format(mContext.getString(R.string.x3_months_ago), month, getCurrentUnit(month, mContext, false));
                }
                long years = days / 365;
                return String.format(mContext.getString(R.string.x3_years_ago), years, getCurrentUnit(years, mContext, false));
            }
            }else {

            }

        } catch (ParseException e) {
            e.printStackTrace();
        }

        return "";
    }
    public static String LongToString(Long time) {

            SimpleDateFormat sdf = new SimpleDateFormat("yyyy:MM");
            Date date = new Date(time);
            return sdf.format(date);
    }

    public static String getCurrentYm(){
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM");
        Date currentDate = new Date(System.currentTimeMillis());
        String format = simpleDateFormat.format(currentDate);
        return format;
    }

    /**
     * 获取两个日期的月数差
     * @param fromDate
     * @param toDate
     * @return
     */
    public static int getDifferMonth(Date fromDate, Date toDate) {
        Calendar fromDateCal = Calendar.getInstance();
        Calendar toDateCal = Calendar.getInstance();
        fromDateCal.setTime(fromDate);
        toDateCal.setTime(toDate);

        int fromYear = fromDateCal.get(Calendar.YEAR);
        int toYear = toDateCal.get((Calendar.YEAR));
        if (fromYear == toYear) {
            return Math.abs(fromDateCal.get(Calendar.MONTH) - toDateCal.get(Calendar.MONTH));
        } else {
            int fromMonth = 12 - (fromDateCal.get(Calendar.MONTH) + 1);
            int toMonth = toDateCal.get(Calendar.MONTH) + 1;
            return Math.abs(toYear - fromYear - 1) * 12 + fromMonth + toMonth;
        }
    }


    /**
     * 给日期加上几个月份
     * @param sourceDate
     * @param month
     * @return
     */
    public static String addMonth(Date sourceDate, int month) {
        Calendar c = Calendar.getInstance();
        c.setTime(sourceDate);
        c.add(Calendar.MONTH, month);
        Date time = c.getTime();
        return dateToString(time,"yyyy-MM-dd HH:mm:ss",Locale.getDefault());
    }

}
